﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wjy自制小框架.Common.Pojo;

namespace wjy自制小框架.Web.Demo
{
    /// <summary>
    /// 测试demo
    /// </summary>
    class DemoController
    {
        public DemoService demoService = new DemoService();

        public AjaxResult Start(string path, JObject param)
        {
            switch (path)
            {
                // 查询测试demo列表
                case "list": return list(param);
                // 获取测试demo详细信息
                case "getInfo": return getInfo(param["id"].ToString());
                // 新增测试demo
                case "add": return add(param.ToObject<Demo>());
                // 修改测试demo
                case "edit": return edit(param.ToObject<Demo>());
                // 删除测试demo
                case "remove": return remove(param["ids"].ToObject<string[]>());
            }
            return AjaxResult.error("接口不存在");
        }

        /// <summary>
        /// 查询测试demo列表
        /// </summary>
        private AjaxResult list(JObject param)
        {
            return demoService.selectPage(param);
        }

        /// <summary>
        /// 获取测试demo详细信息
        /// </summary>
        private AjaxResult getInfo(string id)
        {
            return AjaxResult.success(demoService.selectById(id));
        }

        /// <summary>
        /// 新增测试demo
        /// </summary>
        private AjaxResult add(Demo insert)
        {
            long id = demoService.insert(insert);
            return AjaxResult.success(id);
        }

        /// <summary>
        /// 修改测试demo
        /// </summary>
        private AjaxResult edit(Demo update)
        {
            demoService.updateById(update);
            return AjaxResult.success();
        }

        /// <summary>
        /// 删除测试demo
        /// </summary>
        private AjaxResult remove(string[] ids)
        {
            demoService.deleteBatchIds(ids);
            return AjaxResult.success();
        }
    }
}
